﻿using Shop.RemoteModel.Category.Model;
using Shop.StoreGatewayModular.Interface;
using WeDonekRpc.ApiGateway.Attr;
using WeDonekRpc.Helper.Validate;
using WeDonekRpc.HttpApiGateway;
using WeDonekRpc.HttpApiGateway.Model;

namespace Shop.StoreGatewayModular.Api
{
    /// <summary>
    /// 后台商品分类
    /// </summary>
    [ApiRouteName("/shop/category/{name}")]
    internal class CategoryApi : ApiController
    {
        private readonly ICategoryService _Service;

        public CategoryApi (ICategoryService service)
        {
            this._Service = service;
        }
        /// <summary>
        /// 添加分类
        /// </summary>
        /// <param name="datum"></param>
        /// <returns></returns>
        public long Add (CategoryAdd datum)
        {
            return this._Service.Add(datum);
        }
        /// <summary>
        /// 删除分类
        /// </summary>
        /// <param name="id"></param>
        public void Delete ([NumValidate("shop.category.id.error", 1)] long id)
        {
            this._Service.Delete(id);
        }
        /// <summary>
        /// 禁用分类
        /// </summary>
        /// <param name="id"></param>
        public void Disable ([NumValidate("shop.category.id.error", 1)] long id)
        {
            this._Service.Disable(id);
        }

        /// <summary>
        /// 启用分类
        /// </summary>
        /// <param name="id"></param>
        public void Enable ([NumValidate("shop.category.id.error", 1)] long id)
        {
            this._Service.Enable(id);
        }
        /// <summary>
        /// 获取分类信息
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public CategoryDatum Get ([NumValidate("shop.category.id.error", 1)] long id)
        {
            return this._Service.Get(id);
        }

        /// <summary>
        /// 获取分类树形完整信息
        /// </summary>
        /// <returns></returns>
        public CategoryFullTree[] GetFullTree ()
        {
            return this._Service.GetFullTree();
        }
        /// <summary>
        /// 获取启用的分类树形
        /// </summary>
        /// <returns></returns>
        public CategoryTree[] GetTree (CategoryGetParam param)
        {
            return this._Service.GetTree(param);
        }
        /// <summary>
        /// 移动分类
        /// </summary>
        /// <param name="param"></param>
        public void Move (LongNullParam<long?> param)
        {
            this._Service.Move(param.Id, param.Value);
        }

        /// <summary>
        /// 修改分类资料
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        public bool Set (LongParam<CategorySet> param)
        {
            return this._Service.Set(param.Id, param.Value);
        }
        /// <summary>
        /// 设置分类的排序位
        /// </summary>
        /// <param name="param"></param>
        public Dictionary<long, int> SetSort (LongParam<int> param)
        {
            return this._Service.SetSort(param.Id, param.Value);
        }
    }
}
